package com.zxy.tcp;

import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.alipay.api.internal.util.AlipaySignature;
import com.zxy.adminlog.UsAdmin_Log;
import com.zxy.business.Query_Data;
import com.zxy.common.Com_Fun;
import com.zxy.common.Com_Para;
import com.zxy.common.EncryptUtil;
import com.zxy.common.MD5Util;
import com.zxy.model.Return_Value;
import com.zxy.pay.AlipayConfig;
import com.zxy.pay.Alipay_now;
import com.zxy.pay.WxPayConfig;

public class ServerPageHttp
{
	private Return_Value		rv			= new Return_Value();
	public static final String	WEB_ROOT	= Com_Para.ApplicationPath
			+ File.separator + "web";
	public String				strIP		= "0.0.0.0";
	public StringBuilder		strUrl		= new StringBuilder();
	public String[]				post_str	= new String[0];
	public String				strResult	= "-1";
	public String				jsonpzxyong	= "";
	private String				is_xml		= "";

	// 检测攻击性字符
	public boolean checkXssChar(String s)
	{
		if(s != null)
		{
			String[] str =
			{ "<", ">", "\"" };// ,"'","(",")"};
			for(String string: str)
			{
				if(s.indexOf(string) != -1)
				{
					return true;
				}
			}
		}
		return false;
	}

	public StringBuilder PageResult()
	{
		String s_guid = "";
		StringBuilder strResult = new StringBuilder("-1");
		StringBuilder returnMessage = new StringBuilder();
		Query_Data gd = new Query_Data(this.rv);
		try
		{
			if((strUrl.indexOf("sub_code=") != -1)
					&& (strUrl.indexOf("param_name=") != -1))
			{
				strResult.delete(0,strResult.length());
				strResult = Center_Data_Rel(strUrl,s_guid,post_str,gd,returnMessage,strIP);
			}
			// 微信支付成功
			else if(strUrl.indexOf("WxPay.html") != -1)
			{
				String strTPost = "";
				for(String strTem: post_str)
				{
					strTPost += "\r\n" + strTem;
				}
				strResult.delete(0,strResult.length());
				strResult = WxPay_Rel(strTPost,strUrl,s_guid,post_str,gd,returnMessage,strIP);
			}
			// 支付宝登录授权
			else if(strUrl.indexOf("aliAuth=tue") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = aliAuth_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 支付宝获取令牌
			else if(strUrl.indexOf("aliToken=true") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = aliToken_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 微信获取令牌
			else if(strUrl.indexOf("wxToken=true") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = wxToken_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 微信获取令牌
			else if(strUrl.indexOf("wxToken2=true") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = wxToken_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 微信公众号获取令牌
			else if(strUrl.indexOf("signature=") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = wxToken_Rel3(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 支付宝支付成功1
			else if(strUrl.indexOf("aliPay=tue") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = aliPay_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 支付宝支付成功2
			else if(strUrl.indexOf("AliPay.html") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = aliPay2_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 支付宝支付成功3
			else if(strUrl.indexOf("aliPay3=true") != -1)
			{
				strResult.delete(0,strResult.length());
				strResult = aliPay3_Rel(strUrl,s_guid,post_str,gd,returnMessage);
			}
			// 其他信息
			else if((!strUrl.toString().trim().equals(""))
					&& (strUrl.toString().trim().indexOf("GET /favicon.ico HTTP/1.1") != -1))
			{
				strResult.delete(0,strResult.length());
				strResult = Send_Error(strUrl,s_guid,post_str,gd,returnMessage);
			}
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
		}
		System.gc();
		return strResult;
	}

	// 发送错误信息
	private StringBuilder Send_Error(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		returnMessage.delete(0,returnMessage.length());
		returnMessage.append("Error请求语法错误");
		return returnMessage;
	}

	// 微信支付成功
	private StringBuilder WxPay_Rel(String strTPost, StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage, String strIP)
	{
		StringBuilder strAryResult = new StringBuilder();
		JSONObject jsob = null;
		try
		{
			if(strTPost.equals(""))
				return new StringBuilder("微信反馈信息为空：");
			else
				jsob = Com_Fun.xmlToJSON(strTPost).getJSONObject("xml");
			if(jsob != null
					&& jsob.getString("result_code").toString().equals("SUCCESS"))
			{
				String param_value = "";
				ArrayList<String> aryParamValue = new ArrayList<String>();
				for(int i = 1;i < 20;i++)
				{
					switch(i)
					{
						case 1:
							param_value = jsob.getString("out_trade_no").toString();
							break;
						case 2:
							param_value = String.valueOf(Float.parseFloat(jsob.getString("total_fee").toString())
									/ 100);
							break;
						case 3:
							param_value = jsob.getString("time_end").toString();
							param_value = Com_Fun.DateTimeStrYYYYMMDDHHmmss(param_value,"yyyyMMddHHmmss");
							break;
						case 4:
							param_value = jsob.getString("transaction_id").toString();
							break;
						case 5:
							param_value = jsob.getString("openid").toString();
							break;
						case 6:
							param_value = jsob.getString("mch_id").toString();
							break;
						case 7:
							param_value = jsob.getString("appid").toString();
							break;
						case 8:
							param_value = jsob.getString("openid").toString();
							break;
						default:
							param_value = "";
					}
					aryParamValue.add(i - 1,param_value);
				}
				/* 签名验证 */
				WxPayConfig wxp = new WxPayConfig();
				StringBuilder stringSignTemp = new StringBuilder();
				stringSignTemp.append("appid=" + jsob.getString("appid")
						+ "&bank_type=" + jsob.getString("bank_type")
						+ "&cash_fee=" + jsob.getString("cash_fee")
						+ "&device_info=" + jsob.getString("device_info")
						+ "&fee_type=" + jsob.getString("fee_type")
						+ "&is_subscribe=" + jsob.getString("is_subscribe")
						+ "&mch_id=" + jsob.getString("mch_id") + "&nonce_str="
						+ jsob.getString("nonce_str") + "&openid="
						+ jsob.getString("openid") + "&out_trade_no="
						+ jsob.getString("out_trade_no") + "&result_code="
						+ jsob.getString("result_code") + "&return_code="
						+ jsob.getString("return_code") + "&time_end="
						+ jsob.getString("time_end") + "&total_fee="
						+ jsob.getString("total_fee") + "&trade_type="
						+ jsob.getString("trade_type") + "&transaction_id="
						+ jsob.getString("transaction_id") + "&key="
						+ wxp.srckey);
				String sign2 = MD5Util.MD5Encode(stringSignTemp.toString(),"UTF-8").toUpperCase();
				if(jsob.getString("sign").equals(sign2))
				{
					strAryResult = gd.GetDataList(Com_Para.sub_code,Com_Para.sub_usercode,"A01_Order_WxPay",aryParamValue,strUrl,"","",strIP,null);
					JSONObject json = null;
					try
					{
						json = new JSONObject(strAryResult.toString());
						if(null != json && !json.has("retcode"))
						{
							org.json.JSONArray scoreObj = (org.json.JSONArray) json.get("A01_Order_WxPay");
							strAryResult.delete(0,strAryResult.length());
							if(scoreObj.length() > 0
									&& ((JSONObject) scoreObj.get(0)).getString("s_result").equals("1"))
							{
								strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"1\",\"error_desc\":\"微信支付成功\"}]}");
							}else
							{
								strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"0\",\"error_desc\":\"微信支付失败,"
										+ ((JSONObject) scoreObj.get(0)).getString("error_desc")
										+ "\"}]}");
								this.rv.err_desc = strAryResult;
								this.rv.s_result = 0;
							}
						}
					}
					catch(Exception ess)
					{
						strAryResult.delete(0,strAryResult.length());
						strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"0\",\"error_desc\":\"微信支付失败,"
								+ json.getString("A01_Order_WxPay") + ";"
								+ ess.getMessage() + "\"}]}");
						this.rv.err_desc = strAryResult;
						this.rv.s_result = 0;
					}
				}else
				{
					strAryResult.delete(0,strAryResult.length());
					strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"0\",\"error_desc\":\"微信支付失败,微信签名校验失败\"}]}");
					this.rv.err_desc = strAryResult;
					this.rv.s_result = 0;
				}
			}else
			{
				strAryResult.delete(0,strAryResult.length());
				strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"0\",\"error_desc\":\"微信反馈信息错误："
						+ strTPost + "\"}]}");
				this.rv.err_desc = strAryResult;
				this.rv.s_result = 0;
			}
		}
		catch(JSONException e)
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Order_WxPay\":[{\"s_result\":\"0\",\"error_desc\":\"微信反馈信息错误："
					+ e.getMessage() + "\"}]}");
			this.rv.err_desc = strAryResult;
			this.rv.s_result = 0;
		}
		return strAryResult;
	}

	// 支付宝支付成功2
	private StringBuilder aliPay2_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		String[] strParameter = post_str;
		Map<String, String> params = new HashMap<String, String>();
		// System.out.println("*****支付宝异步通知开始*****");
		for(int i = 0;i < strParameter.length;i++)
		{
			String[] strTemPar = strParameter[i].split("=");
			if(strTemPar.length > 1)
			{
				if(strParameter[i].indexOf("sign=") == 0)
				{
					String strSign = strParameter[i].substring(5,strParameter[i].length());
					params.put("sign",strSign);
				}else
				{
					params.put(strTemPar[0],strTemPar[1]);
				}
			}
		}
		// *****支付宝异步通知验签*****";
		boolean signVerified = AlipaySignature.rsaCheckV1(params,AlipayConfig.ALIPAY_PUBLIC_KEY,"UTF-8",AlipayConfig.SIGNTYPE);
		if((params.get("total_amount") != null)
				&& (params.get("total_amount").toString() != "")
				&& (params.get("gmt_payment") != null)
				&& (params.get("gmt_payment").toString() != "")
				&& (params.get("trade_no") != null)
				&& (params.get("trade_no").toString() != "")
				&& (params.get("auth_app_id") != null)
				&& (params.get("auth_app_id").toString() != "")
				&& (params.get("app_id") != null)
				&& (params.get("app_id").toString() != "")
				&& (params.get("out_trade_no") != null)
				&& (params.get("out_trade_no").toString() != ""))
		{
			String param_value = "";
			ArrayList<String> aryParamValue = new ArrayList<String>();
			for(int i = 1;i < 20;i++)
			{
				switch(i)
				{
					case 1:
						param_value = java.util.Objects.equals(params.get("out_trade_no"),null) ? "" : (String) params.get("out_trade_no");
						break;
					case 2:
						param_value = java.util.Objects.equals(params.get("total_amount"),null) ? "" : (String) params.get("total_amount");
						break;
					case 3:
						param_value = java.util.Objects.equals(params.get("gmt_payment"),null) ? "" : (String) params.get("gmt_payment");
						break;
					case 4:
						param_value = java.util.Objects.equals(params.get("trade_no"),null) ? "" : (String) params.get("trade_no");
						break;
					case 5:
						param_value = java.util.Objects.equals(params.get("auth_app_id"),null) ? "" : (String) params.get("auth_app_id");
						break;
					case 6:
						param_value = java.util.Objects.equals(params.get("seller_id"),null) ? "" : (String) params.get("seller_id");
						break;
					case 7:
						param_value = java.util.Objects.equals(params.get("app_id"),null) ? "" : (String) params.get("app_id");
						break;
					case 8:
						param_value = java.util.Objects.equals(params.get("buyer_id"),null) ? "" : (String) params.get("buyer_id");
						break;
					default:
						param_value = "";
				}
				aryParamValue.add(i - 1,param_value);
			}

			if(signVerified)
			{
				strAryResult = gd.GetDataList(Com_Para.sub_code,Com_Para.sub_usercode,"A01_Order_AliPay",aryParamValue,strUrl,"","",strIP,null);
				JSONObject json = null;
				try
				{
					json = new JSONObject(strAryResult.toString());
					if(null != json && !json.has("retcode"))
					{
						org.json.JSONArray scoreObj = (org.json.JSONArray) json.get("A01_Order_AliPay");
						if(scoreObj.length() > 0
								&& ((JSONObject) scoreObj.get(0)).getString("s_result").equals("1"))
						{
							strAryResult.delete(0,strAryResult.length());
							strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"1\",\"error_desc\":\"支付宝支付成功\"}]}");
						}else
						{
							strAryResult.delete(0,strAryResult.length());
							strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败,"
									+ ((JSONObject) scoreObj.get(0)).getString("error_desc")
									+ "\"}]}");
							this.rv.err_desc = strAryResult;
							this.rv.s_result = 0;
						}
					}
				}
				catch(Exception ess)
				{
					strAryResult.delete(0,strAryResult.length());
					strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败,"
							+ json.getString("A01_Order_AliPay") + ";"
							+ ess.getMessage() + "\"}]}");
					this.rv.err_desc = strAryResult;
					this.rv.s_result = 0;
				}
			}else
			{
				strAryResult.delete(0,strAryResult.length());
				strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付失败,支付宝签名校验失败\"}]}");
				this.rv.err_desc = strAryResult;
				this.rv.s_result = 0;
			}
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝反馈信息错误："
					+ strUrl + "\"}]}");
			this.rv.err_desc = strAryResult;
			this.rv.s_result = 0;
		}
		return strAryResult;
	}

	// 支付宝支付成功3
	private StringBuilder aliPay3_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Map<String, String> params = new HashMap<String, String>();
		JSONObject json = null;
		try
		{
			json = new JSONObject(post_str[0]);
			JSONObject trade_app = json.getJSONObject("alipay_trade_app_pay_response");
			@SuppressWarnings("unchecked")
			Iterator<String> sIterator = trade_app.keys();
			while(sIterator.hasNext())
			{
				String key = sIterator.next();
				String value = trade_app.getString(key);
				params.put(key,value);
			}
			params.put("sign",json.getString("sign").toString().replace(" ","+"));
		}
		catch(Exception e)
		{
		}
		if((params.get("code") != null
				&& params.get("code").toString().equals("10000"))
				&& (params.get("total_amount").toString() != "")
				&& (params.get("timestamp") != null)
				&& (params.get("timestamp").toString() != "")
				&& (params.get("trade_no") != null)
				&& (params.get("trade_no").toString() != "")
				&& (params.get("auth_app_id") != null)
				&& (params.get("auth_app_id").toString() != "")
				&& (params.get("app_id") != null)
				&& (params.get("app_id").toString() != "")
				&& (params.get("out_trade_no") != null)
				&& (params.get("out_trade_no").toString() != ""))
		{
			String param_value = "";
			ArrayList<String> aryParamValue = new ArrayList<String>();
			for(int i = 1;i < 20;i++)
			{
				switch(i)
				{
					case 1:
						param_value = java.util.Objects.equals(params.get("out_trade_no"),null) ? "" : (String) params.get("out_trade_no");
						break;
					case 2:
						param_value = java.util.Objects.equals(params.get("total_amount"),null) ? "" : (String) params.get("total_amount");
						break;
					case 3:
						param_value = java.util.Objects.equals(params.get("timestamp"),null) ? "" : Com_Fun.s_decode((String) params.get("timestamp"),Com_Para.U_CODE);
						break;
					case 4:
						param_value = java.util.Objects.equals(params.get("trade_no"),null) ? "" : (String) params.get("trade_no");
						break;
					case 5:
						param_value = java.util.Objects.equals(params.get("auth_app_id"),null) ? "" : (String) params.get("auth_app_id");
						break;
					case 6:
						param_value = java.util.Objects.equals(params.get("seller_id"),null) ? "" : (String) params.get("seller_id");
						break;
					case 7:
						param_value = java.util.Objects.equals(params.get("app_id"),null) ? "" : (String) params.get("app_id");
						break;
					case 8:
						param_value = "-1";
						break;
					default:
						param_value = "";
				}
				aryParamValue.add(i - 1,param_value);
			}
			// "*****支付宝同步通知*****");
			@SuppressWarnings("unused")
			boolean signVerified = AlipaySignature.rsaCheckV1(params,AlipayConfig.ALIPAY_PUBLIC_KEY,"UTF-8",AlipayConfig.SIGNTYPE);
			if(true && params.get("msg").toString().equals("Success"))
			{
				strAryResult = gd.GetDataList(Com_Para.sub_code,Com_Para.sub_usercode,"A01_Order_AliPay",aryParamValue,strUrl,"","",strIP,null);
				try
				{
					json = new JSONObject(strAryResult.toString());
					if(null != json && !json.has("retcode"))
					{
						org.json.JSONArray scoreObj = (org.json.JSONArray) json.get("A01_Order_AliPay");
						if(scoreObj.length() > 0
								&& ((JSONObject) scoreObj.get(0)).getString("s_result").equals("1"))
						{
							strAryResult.delete(0,strAryResult.length());
							strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"1\",\"error_desc\":\"支付宝支付成功\"}]}");
						}else
						{
							strAryResult.delete(0,strAryResult.length());
							strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败:"
									+ ((JSONObject) scoreObj.get(0)).getString("error_desc")
									+ "\"}]}");
						}
					}
				}
				catch(Exception ess)
				{
					strAryResult.delete(0,strAryResult.length());
					strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败:"
							+ json.getString("A01_Order_AliPay") + ";"
							+ ess.getMessage() + "\"}]}");
				}
			}else
			{
				strAryResult.delete(0,strAryResult.length());
				strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败:验签失败\"}]}");
			}
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝支付失败:"
					+ strUrl + "\"}]}");
		}
		return strAryResult;
	}

	// 支付宝支付成功1
	private StringBuilder aliPay_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		String strGUIDS = Com_Fun.Get_New_GUID();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess += strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}

		if((htParam.get("total_amount") != null)
				&& (htParam.get("total_amount").toString() != "")
				&& (htParam.get("gmt_payment") != null)
				&& (htParam.get("gmt_payment").toString() != "")
				&& (htParam.get("trade_no") != null)
				&& (htParam.get("trade_no").toString() != "")
				&& (htParam.get("auth_app_id") != null)
				&& (htParam.get("auth_app_id").toString() != "")
				&& (htParam.get("app_id") != null)
				&& (htParam.get("app_id").toString() != "")
				&& (htParam.get("out_trade_no") != null)
				&& (htParam.get("out_trade_no").toString() != "")
				&& (htParam.get("buyer_id") != null)
				&& (htParam.get("buyer_id").toString() != ""))
		{
			String param_name = "A01_Order_AliPay";
			String sub_code = Com_Para.sub_code;
			String sub_usercode = Com_Para.sub_usercode;
			String param_value = "";
			ArrayList<String> aryParamValue = new ArrayList<String>();
			for(int i = 1;i < 20;i++)
			{
				switch(i)
				{
					case 1:
						param_value = java.util.Objects.equals(htParam.get("out_trade_no"),null) ? "" : (String) htParam.get("out_trade_no");
						break;
					case 2:
						param_value = java.util.Objects.equals(htParam.get("total_amount"),null) ? "" : (String) htParam.get("total_amount");
						break;
					case 3:
						param_value = java.util.Objects.equals(htParam.get("gmt_payment"),null) ? "" : Com_Fun.s_decode((String) htParam.get("gmt_payment"),Com_Para.U_CODE);
						break;
					case 4:
						param_value = java.util.Objects.equals(htParam.get("trade_no"),null) ? "" : (String) htParam.get("trade_no");
						break;
					case 5:
						param_value = java.util.Objects.equals(htParam.get("auth_app_id"),null) ? "" : (String) htParam.get("auth_app_id");
						break;
					case 6:
						param_value = java.util.Objects.equals(htParam.get("seller_id"),null) ? "" : (String) htParam.get("seller_id");
						break;
					case 7:
						param_value = java.util.Objects.equals(htParam.get("app_id"),null) ? "" : (String) htParam.get("app_id");
						break;
					case 8:
						param_value = java.util.Objects.equals(htParam.get("buyer_id"),null) ? "" : (String) htParam.get("buyer_id");
						break;
					default:
						param_value = "";
				}
				aryParamValue.add(i - 1,param_value);
			}
			String delay_data = "";
			String delay_code = "";
			if((htParam.get("trade_status") != null)
					&& htParam.get("trade_status").toString().equals("TRADE_SUCCESS"))
			{
				strAryResult = gd.GetDataList(sub_code,sub_usercode,param_name,aryParamValue,strUrl,delay_data,delay_code,strIP,null);
			}else
			{
				strAryResult.delete(0,strAryResult.length());
				strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\""
						+ strGUIDS + "支付失败："
						+ htParam.get("trade_status").toString() + "\"}]}");
			}
		}else if((htParam.get("trade_status") != null)
				&& htParam.get("trade_status").toString().equals("TRADE_SUCCESS"))
		{

			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"1\",\"error_desc\":\""
					+ strGUIDS + "支付成功：" + strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder(strGUIDS
					+ "支付成功数据[" + strPaySuccess + "]"));
			uL.WriteLog();
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Order_AliPay\":[{\"s_result\":\"0\",\"error_desc\":\"支付失败数据："
					+ strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder(strGUIDS
					+ "支付失败数据[" + strPaySuccess + "]"));
			uL.WriteLog();
		}
		return strAryResult;
	}

	// 微信授权2
	@SuppressWarnings("unused")
	private StringBuilder wxToken2_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess += strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}
		if((htParam.get("param_value1") != null)
				&& (htParam.get("param_value1") != ""))
		{
			WxPayConfig an = new WxPayConfig();
			strAryResult = an.Wx_Login2(htParam.get("param_value1").toString(),htParam.get("param_value2").toString(),htParam.get("param_value3").toString());// an.aliToken(htParam.get("param_value1").toString());

		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Wx_Login_OK\":[{\"s_result\":\"0\",\"error_desc\":\"微信获取令牌失败数据;"
					+ strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("微信授权失败数据["
					+ strPaySuccess + "]"));
			try
			{
				uL.WriteLog();
			}
			catch(IOException e)
			{
			}
		}
		return strAryResult;
	}

	// 微信授权1
	private StringBuilder wxToken_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess = strPaySuccess + strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}
		if((htParam.get("param_value1") != null)
				&& (htParam.get("param_value1") != ""))
		{
			WxPayConfig an = new WxPayConfig();
			strAryResult = an.Wx_Login(htParam.get("param_value1").toString());// an.aliToken(htParam.get("param_value1").toString());
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Wx_Login_OK\":[{\"s_result\":\"0\",\"error_desc\":\"微信获取令牌失败数据;"
					+ strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("微信授权失败数据["
					+ strPaySuccess + "]"));
			try
			{
				uL.WriteLog();
			}
			catch(IOException e)
			{
			}
		}
		return strAryResult;
	}

	// 微信公众号授权3
	private StringBuilder wxToken_Rel3(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess = strPaySuccess + strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}
		if(java.util.Objects.equals(htParam.get("signature"),null)
				|| htParam.get("signature").equals(""))
		{
			strAryResult.append("error no signature");
		}else if(java.util.Objects.equals(htParam.get("timestamp"),null)
				|| htParam.get("timestamp").equals(""))
		{
			strAryResult.append("error no timestamp");
		}else if(java.util.Objects.equals(htParam.get("nonce"),null)
				|| htParam.get("nonce").equals(""))
		{
			strAryResult.append("error no nonce");
		}else if(java.util.Objects.equals(htParam.get("echostr"),null)
				|| htParam.get("echostr").equals(""))
		{
			strAryResult.append("error no echostr");
		}else
		{
			WxPayConfig an = new WxPayConfig();
			strAryResult = an.Wx_Login_GZH(htParam);
		}
		return strAryResult;
	}

	// 支付宝获取令牌
	private StringBuilder aliToken_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess = strPaySuccess + strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}
		if((htParam.get("param_value1") != null)
				&& (htParam.get("param_value1") != ""))
		{
			Alipay_now an = new Alipay_now();
			strAryResult = an.Ali_Login(htParam.get("param_value1").toString());// an.aliToken(htParam.get("param_value1").toString());
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Ali_Login_OK\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝获取令牌失败数据;"
					+ strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("支付宝授权失败数据["
					+ strPaySuccess + "]"));
			try
			{
				uL.WriteLog();
			}
			catch(IOException e)
			{
			}
		}
		return strAryResult;
	}

	// 支付宝登录授权
	private StringBuilder aliAuth_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage) throws Exception
	{
		StringBuilder strAryResult = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		String strPaySuccess = "";
		for(String strTemV: strUrl.toString().split("&"))
		{
			strPaySuccess = strPaySuccess + strTemV + "\r\n";
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length > 1)
			{
				htParam.put(strTemPar[0],strTemPar[1]);
			}
		}
		if((htParam.get("auth_code") != null)
				&& (htParam.get("auth_code") != ""))
		{
			String param_name = "A01_Ali_Login";
			String sub_code = Com_Para.sub_code;
			String sub_usercode = Com_Para.sub_usercode;
			String param_value = "";
			ArrayList<String> aryParamValue = new ArrayList<String>();
			for(int i = 1;i < 20;i++)
			{
				switch(i)
				{
					case 1:
						param_value = java.util.Objects.equals(htParam.get("auth_code"),null) ? "" : (String) htParam.get("auth_code");
						break;
					default:
						param_value = "";
				}

				aryParamValue.add(i - 1,param_value);
			}
			String delay_data = "";
			String delay_code = "";
			strAryResult = gd.GetDataList(sub_code,sub_usercode,param_name,aryParamValue,strUrl,delay_data,delay_code,strIP,null);
		}else
		{
			strAryResult.delete(0,strAryResult.length());
			strAryResult.append("{\"A01_Ali_Login\":[{\"s_result\":\"0\",\"error_desc\":\"支付宝授权失败数据;"
					+ strPaySuccess + "\"}]}");
			UsAdmin_Log uL = new UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("支付宝授权失败数据["
					+ strPaySuccess + "]"));
			try
			{
				uL.WriteLog();
			}
			catch(IOException e)
			{
			}
		}
		return strAryResult;
	}

	// 通用接口信息
	private StringBuilder Center_Data_Rel(StringBuilder strUrl, String s_guid, String[] post_str, Query_Data gd, StringBuilder returnMessage, String strIP) throws Exception
	{
		StringBuilder strAry = new StringBuilder();
		Hashtable<String, String> htParam = new Hashtable<String, String>();
		for(String strTemV: strUrl.toString().split("&"))
		{
			String[] strTemPar = strTemV.split("=");
			if(strTemPar.length == 2)
				htParam.put(strTemPar[0],strTemPar[1]);
			else
				htParam.put(strTemPar[0],"");
		}
		String sub_code = java.util.Objects.equals(htParam.get("sub_code"),null) ? "" : (String) htParam.get("sub_code");
		String sub_usercode = java.util.Objects.equals(htParam.get("sub_usercode"),null) ? "" : (String) htParam.get("sub_usercode");
		String delay_data = java.util.Objects.equals(htParam.get("delay_data"),null) ? "" : (String) htParam.get("delay_data");
		String delay_code = java.util.Objects.equals(htParam.get("delay_code"),null) ? "" : (String) htParam.get("delay_code");
		String param_name = java.util.Objects.equals(htParam.get("param_name"),null) ? "" : (String) htParam.get("param_name");
		String session_id = java.util.Objects.equals(htParam.get("session_id"),null) ? "" : (String) htParam.get("session_id");
		String login_id = java.util.Objects.equals(htParam.get("login_id"),null) ? "" : (String) htParam.get("login_id");
		String param_dbname = java.util.Objects.equals(htParam.get("param_dbname"),null) ? "" : (String) htParam.get("param_dbname");
		gd.pageNumber = java.util.Objects.equals(htParam.get("pageNumber"),null) ? 0 : Integer.valueOf(htParam.get("pageNumber"));
		gd.pageSize = java.util.Objects.equals(htParam.get("pageSize"),null) ? 0 : Integer.valueOf(htParam.get("pageSize"));
		// Oracle或国产数据库，所有参数需要带param_dbname
		if(!param_dbname.equals(""))
			gd.param_dbname = param_dbname + ".";
		is_xml = java.util.Objects.equals(htParam.get("is_xml"),null) ? "" : (String) htParam.get("is_xml");
		String jsonpzxyong = java.util.Objects.equals(htParam.get("jsoncallback"),null) ? "" : (String) htParam.get("jsoncallback");
		s_guid = java.util.Objects.equals(htParam.get("s_guid"),null) ? "" : (String) htParam.get("s_guid");
		this.rv.param_name = param_name;
		// 是否需要登录flag
		boolean bFlag = false;
		if((Com_Para.Is_UserLogin != "") && ((Com_Para.Is_UserLogin.indexOf("["
				+ param_name + "]") != -1)
				|| (Com_Fun.s_decode(Com_Para.Is_UserLogin,Com_Para.U_CODE).indexOf("["
						+ param_name + "]") != -1))){
			bFlag = true;
		}
		// 传递in 参数
		ArrayList<String> aryParamValue = new ArrayList<String>();
		for(int i = 1;i < 101;i++){
			boolean tembFlag = false;
			String strVS = "";
			if(htParam.containsKey("param_value" + String.valueOf(i))){
				strVS = (String) htParam.get("param_value" + String.valueOf(i));
				if(i == 1 || i == 2)
					strVS = Com_Fun.getParam_value1(Com_Fun.s_decode(strVS.trim()));
				tembFlag = true;
			}
			else{
				for(String temstr: post_str){
					if(temstr.indexOf("param_value" + String.valueOf(i)
							+ "=") == 0)
					{
						tembFlag = true;
					}else if(temstr.equals("jsonpzxyong")){
						jsonpzxyong = temstr.split("=")[1];
					}
					if((temstr.indexOf("param_value" + String.valueOf(i)
							+ "=") == 0) && (temstr.split("=").length > 1))
					{
						strVS = temstr.split("=")[1];
						if(i == 1 || i == 2)
							strVS = Com_Fun.getParam_value1(Com_Fun.s_decode(strVS));
						break;
					}
				}
			}
			if(!tembFlag)
				break;
			//用户登录密码加密，密码为第2个参数 param_value2固定位置
			if((bFlag) && (i == 2)){
				if(Com_Para.EncryptUtilType == 1)
					strVS = EncryptUtil.getSM32(Com_Fun.s_decode(strVS));
				else if(Com_Para.EncryptUtilType == 2)
					strVS = EncryptUtil.getMd5(Com_Fun.s_decode(strVS)).toLowerCase();
				else if(Com_Para.EncryptUtilType == 3)
					strVS = com.zxy.common.CustomSHA256PasswordValidator.encode(Com_Fun.s_decode(strVS));
			}
			aryParamValue.add(i - 1,strVS);
		}

		// 用户登录接口
		if(bFlag){
			gd.session_id = Com_Fun.Get_New_GUID().replace("-","");
			//判断账号是否已锁定
			if(!java.util.Objects.equals(login_id,"")){
				String temerror = Com_Fun.login_lock(login_id,strIP);
				if(temerror.length() > 0){
					strAry.delete(0,strAry.length());
					strAry.append("{\"" + param_name + "\":[{\""
						+ Com_Fun.getLowUpp("session_id") + "\":\"\",\""
						+ Com_Fun.getLowUpp("s_result") + "\":\"0\",\""
						+ Com_Fun.getLowUpp("error_desc")
						+ "\":\""+Com_Fun.s_encode(temerror)+"\"}]}");
				}
			}
		}
		// 非登录接口但需要session_id验证
		else if((Com_Para.Login_Session == 1)
				&& (Com_Fun.GetInterSession(param_name))){
			gd.session_id = session_id;
			if((session_id.equals(""))
				|| (!Com_Fun.HadSession(session_id,login_id))){
				strAry.delete(0,strAry.length());
				strAry.append("{\"" + param_name + "\":[{\""
					+ Com_Fun.getLowUpp("session_id") + "\":\"\",\""
					+ Com_Fun.getLowUpp("s_result") + "\":\"0\",\""
					+ Com_Fun.getLowUpp("error_desc")
					+ "\":\""+Com_Fun.s_encode("用户未登陆或已超时,请重新登陆")+"\"}]}");
			}
		}
		// 获取数据接口
		if(strAry.length() == 0)
			strAry = gd.GetDataList(sub_code,sub_usercode,param_name,aryParamValue,strUrl,delay_data,delay_code,strIP,htParam);
		// jsonp格式
		if(!jsonpzxyong.equals(""))
		{
			strAry.insert(0,jsonpzxyong + "(").append(")");
		}
		if(this.rv.s_result == 1)
			this.rv = gd.rv;
		// 转为xml输出格式
		if(is_xml.equals("1"))
		{
			String temMsg = strAry.toString();
			JSONObject jso = null;
			jso = new JSONObject(temMsg);
			temMsg = Com_Fun.JSONToXml(jso.get(param_name).toString(),param_name);
			strAry.delete(0,strAry.length());
			strAry.append(temMsg);
		}
		htParam.clear();
		htParam = null;
		// 清理垃圾内存
		System.gc();
		return strAry;
	}
}